/* eslint-disable no-multiple-empty-lines */
import * as types from './mutations-types'
import axios from 'axios'
import store from "./index";

const matutaions = {
   [types.NAVIGATION_BAR_DATA](state, {objName, data}) {
      if (!state.navigationbardata[objName]) {
         state.navigationbardata[objName] = data
      }
   },
   [types.WATERFALL_DATA](state, {skip = 0, limit = 8} = {}) {
      state.WaterfallData['skip'] = skip
      state.WaterfallData['limit'] = limit
   },
   [types.DETAILS_PAGE_REQUEST_DATA](state, {data}) {
      if (Array.isArray(state.DetailsPageData)) {
         state.DetailsPageData.push(...data)
         return
      }
      state.DetailsPageData = data
   },
   [types.CLOSE_LAZYLOAD](state, {isClose}) {
      state.closeLazyload = isClose
   },
   [types.DISPLAYFOOTER](state, {isdisplay}) {
      state.displayFooter = isdisplay
   },
   [types.NAVIGATION_BAR_DATA_CLEAR](state) {
      state.DetailsPageData = ''
   },
   [types.SET_PARAMETER](state, {obj}) {
      state.parameter = obj
   },
   [types.FILTER_DATA](state, {obj}) {
      state.filterData = obj
   },
   [types.DISPLLAY_LOADING](state, boolean) {
      state.display_loading = boolean
   },
   [types.CONTENT_CLOSE](state, boolean) {
      state.content_close = boolean
   },
   [types.GET_RUL](state, url) {
      state.getUrl = url
   },
   [types.CRUMBS_NAME](state, name) {
      state.crumbsName[1]['NavName'] = name
   },
   [types.DETAILS_DATA](state, {key, data}) {
      if (!state.detailsData[key]) {
         state.detailsData[key] = data
      }
   },
   [types.SPECIFICATION_PARAMETER](state, {key, data}) {
      if (!state.SpecificationParameter[key]) {
         state.SpecificationParameter[key] = data
      }
   },
   [types.FAQ_DATA](state, {key, data}) {
      if (!state.FAQ_DATA[key]) {
         state.FAQ_DATA[key] = data
      }
   },
   [types.BEFORE_ROUTER](state, router) {
      state.beforeRouter = router
   },
   [types.LOGIN_MESSAGE](state, obj) {
      state.loginMessage = obj
   },
   [types.ADD_COOKIE](state, obj) {
      state.addCookie = obj
   },
   [types.GET_USER](state, user_id) {
      axios.get('/apis/user/information', {
         params: {
            id: user_id
         }
      }).then(res => {
         state.loginMessage = res.data
      })
   },
   [types.COLLECTION_DATA](state, {id, data, path}) {
      state.collectionData["id"] = id
      state.collectionData["data"] = data
      state.collectionData["path"] = path
   },
   [types.LOGIN_STATE](state, isClose) {
      state.loginState = isClose
   },
   [types.USER_COLLECTION](state, obj) {
      state.userCollection = obj
   },
   [types.NAVIGATION_FIELD](state, field) {
      state.navigationField = field
   },
   [types.CLEAR_DATAILSPAGEDATA](state) {
      state.DetailsPageData = ''
      state.WaterfallData = {
         skip: 0,
         limit: 8
      }
   }
}

export default matutaions
